Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telemetry (#905) #918

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft

Telemetry (#905) #918

wants to merge 7 commits into from

Conversation

wende
Copy link

@wende wende commented Dec 6, 2024

Relates to #905

@wende wende requested a review from FelonEkonom December 6, 2024 11:20
using :telemetry.span
Comment on lines +51 to +89
@tag :telemetry

setup %{links: links} do
ref = make_ref()

events =
for event <- @events,
step <- @steps do
[:membrane, :element, event, step]
end

:telemetry.attach_many(ref, events, &TelemetryListener.handle_event/4, %{
dest: self(),
ref: ref
})

pid = Testing.Pipeline.start_link_supervised!(spec: links)
:ok = Testing.Pipeline.terminate(pid)
[ref: ref]
end

# Test each lifecycle step for each element type
for element_type <- @paths,
event <- @events do
test "#{element_type}/#{event}", %{ref: ref} do
element_type = unquote(element_type)
event = unquote(event)

assert_receive {^ref, :telemetry_ack,
{[:membrane, :element, ^event, :start], meta, %{path: [_, ^element_type]}}}

assert meta.system_time > 0

assert_receive {^ref, :telemetry_ack,
{[:membrane, :element, ^event, :stop], meta, %{path: [_, ^element_type]}}}

assert meta.duration > 0
end
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tag :telemetry will have impact only on the first test defined after it, so it should be moved inside for statement

assert_receive {^ref, :telemetry_ack,
{[:membrane, :element, ^event, :stop], meta, %{path: [_, ^element_type]}}}

assert meta.duration > 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the execution of the callback is really fast, the duration can be 0 and it won't be a bug. I would rather check if it is not a negative number.

assert_receive {^ref, :telemetry_ack,
{[:membrane, :element, ^event, :start], meta, %{path: [_, ^element_type]}}}

assert meta.system_time > 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if we want to have system_time in a metadata, maybe monotonic_time would be better?

Comment on lines +37 to +43
links = [
child(:source, %Testing.Source{output: [~c"a", ~c"b", ~c"c"]})
|> child(:filter, %TestFilter{target: self()})
|> child(:sink, Testing.Sink)
]

[links: links, ref: ref]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend you to rename links to spec in this file, this will be more consistent with the naming convention used in the other places in membrane

Comment on lines +15 to +25
def_input_pad :input, flow_control: :manual, accepted_format: _any, demand_unit: :buffers
def_output_pad :output, flow_control: :manual, accepted_format: _any
def_options target: [spec: pid()]

@impl true
def handle_demand(_pad, size, _unit, _context, state) do
{[demand: {:input, size}], state}
end

@impl true
def handle_buffer(_pad, _buffer, _context, state), do: {[], state}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove flow_control: :manual option (so it will be set to the default :auto) and remove handle_demand implementation - If you do so the element should be as useful as it is right now

Comment on lines +141 to +143
Telemetry.report_span :element, :terminate do
apply(module, callback, args)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This apply executes all custom callbacks implemented in the membrane components, not only terminate (but handle_terminate is executed here as well as the rest of the handle_* callbacks) and not only in Elements, but also in Bins and Pipelines. Take a look at the path to the file or module name: there is no element in them, so it suggests that this code is used not only in elements.

Suggested change
Telemetry.report_span :element, :terminate do
apply(module, callback, args)
end
component_type =
case state do
%Membrane.Core.Element.State{} -> :element
# the same for bin and pipeline
end
Telemetry.report_span component_type, callback do
apply(module, callback, args)
end

Doing it this way will emit event for ALL callbacks and I think this is the thing we want to do

Comment on lines +99 to +101
Telemetry.report_span :bin, :init do
do_init(options)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we will have an appropriate span for handle_init in CallbackHandler, there is no need for span for :init here

@FelonEkonom
Copy link
Member

I took a brief look at your changes and I commented things that caught my attention

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants